<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveSupport::Duration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActiveSupport::Duration 
            
                <span class="parent">&lt; 
                    
                    ProxyObject
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/activesupport/lib/active_support/duration_rb.html">activesupport/lib/active_support/duration.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>Provides accurate date and time measurements using <a
href="../Date.html#method-i-advance">Date#advance</a> and <a
href="../Time.html#method-i-advance">Time#advance</a>, respectively. It
mainly supports the methods on <a href="../Numeric.html">Numeric</a>.</p>

<pre>1.month.ago       # equivalent to Time.now.advance(months: -1)</pre>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>#</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Duration.html#method-i-2B">+</a>,
              </li>
            
              
              <li>
                <a href="Duration.html#method-i-2D">-</a>,
              </li>
            
              
              <li>
                <a href="Duration.html#method-i-3D-3D">==</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Duration.html#method-i-ago">ago</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>F</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Duration.html#method-i-from_now">from_now</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Duration.html#method-i-since">since</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>U</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Duration.html#method-i-until">until</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    
      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [RW]
            </td>
            <td class='attr-name'>parts</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [RW]
            </td>
            <td class='attr-name'>value</td>
            <td class='attr-desc'></td>
          </tr>
        
      </table>
    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-2B">
            
              <b>+</b>(other)
            
            <a href="Duration.html#method-i-2B" name="method-i-2B" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Adds another <a href="Duration.html">Duration</a> or a <a
href="../Numeric.html">Numeric</a> to this <a
href="Duration.html">Duration</a>. <a href="../Numeric.html">Numeric</a>
values are treated as seconds.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-2B_source')" id="l_method-i-2B_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/6ee03a40bbb95c68d7517098b1e215f08ad82fb5/activesupport/lib/active_support/duration.rb#L19" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-2B_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/duration.rb, line 19</span>
<span class="ruby-keyword">def</span> <span class="ruby-operator">+</span>(<span class="ruby-keyword ruby-title">other</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-constant">Duration</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">other</span>
    <span class="ruby-constant">Duration</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">value</span>, <span class="ruby-ivar">@parts</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">parts</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-constant">Duration</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">other</span>, <span class="ruby-ivar">@parts</span> <span class="ruby-operator">+</span> [[<span class="ruby-value">:seconds</span>, <span class="ruby-identifier">other</span>]])
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-2D">
            
              <b>-</b>(other)
            
            <a href="Duration.html#method-i-2D" name="method-i-2D" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Subtracts another <a href="Duration.html">Duration</a> or a <a
href="../Numeric.html">Numeric</a> from this <a
href="Duration.html">Duration</a>. <a href="../Numeric.html">Numeric</a>
values are treated as seconds.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-2D_source')" id="l_method-i-2D_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/6ee03a40bbb95c68d7517098b1e215f08ad82fb5/activesupport/lib/active_support/duration.rb#L29" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-2D_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/duration.rb, line 29</span>
<span class="ruby-keyword">def</span> <span class="ruby-operator">-</span>(<span class="ruby-keyword ruby-title">other</span>)
  <span class="ruby-keyword">self</span> <span class="ruby-operator">+</span> (<span class="ruby-operator">-</span><span class="ruby-identifier">other</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-3D-3D">
            
              <b>==</b>(other)
            
            <a href="Duration.html#method-i-3D-3D" name="method-i-3D-3D" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns <code>true</code> if <code>other</code> is also a <a
href="Duration.html">Duration</a> instance with the same
<code>value</code>, or if <code>other == value</code>.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-3D-3D_source')" id="l_method-i-3D-3D_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/6ee03a40bbb95c68d7517098b1e215f08ad82fb5/activesupport/lib/active_support/duration.rb#L44" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-3D-3D_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/duration.rb, line 44</span>
<span class="ruby-keyword">def</span> <span class="ruby-operator">==</span>(<span class="ruby-keyword ruby-title">other</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-constant">Duration</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">other</span>
    <span class="ruby-identifier">other</span>.<span class="ruby-identifier">value</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">value</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">other</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">value</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-ago">
            
              <b>ago</b>(time = ::Time.current)
            
            <a href="Duration.html#method-i-ago" name="method-i-ago" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Calculates a new <a href="../Time.html">Time</a> or <a
href="../Date.html">Date</a> that is as far in the past as this <a
href="Duration.html">Duration</a> represents.</p>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="Duration.html#method-i-until">until</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-ago_source')" id="l_method-i-ago_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/6ee03a40bbb95c68d7517098b1e215f08ad82fb5/activesupport/lib/active_support/duration.rb#L67" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-ago_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/duration.rb, line 67</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">ago</span>(<span class="ruby-identifier">time</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">current</span>)
  <span class="ruby-identifier">sum</span>(<span class="ruby-number">-1</span>, <span class="ruby-identifier">time</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-from_now">
            
              <b>from_now</b>(time = ::Time.current)
            
            <a href="Duration.html#method-i-from_now" name="method-i-from_now" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-since">
            
              <b>since</b>(time = ::Time.current)
            
            <a href="Duration.html#method-i-since" name="method-i-since" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Calculates a new <a href="../Time.html">Time</a> or <a
href="../Date.html">Date</a> that is as far in the future as this <a
href="Duration.html">Duration</a> represents.</p>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="Duration.html#method-i-from_now">from_now</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-since_source')" id="l_method-i-since_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/6ee03a40bbb95c68d7517098b1e215f08ad82fb5/activesupport/lib/active_support/duration.rb#L60" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-since_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/duration.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">since</span>(<span class="ruby-identifier">time</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">current</span>)
  <span class="ruby-identifier">sum</span>(<span class="ruby-number">1</span>, <span class="ruby-identifier">time</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-until">
            
              <b>until</b>(time = ::Time.current)
            
            <a href="Duration.html#method-i-until" name="method-i-until" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
                    </div>

    </div>
  </body>
</html>    